<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%category}}".
 *
 * @property integer $id
 * @property integer $p_id
 * @property string $title
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $deleted
 *
 * @property News[] $news
 */
class Category extends BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%category}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['p_id', 'created_at', 'updated_at', 'deleted'], 'integer'],
            [['title', 'created_at', 'updated_at'], 'required'],
            [['title'], 'string', 'max' => 128],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'p_id' => '上级id',
            'title' => 'Title',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted' => '标记删除',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getNews()
    {
        return $this->hasMany(News::className(), ['catid' => 'id']);
    }
}
